from django.http import HttpResponse
from django.shortcuts import render

from blog.models import User


def reg_view(request):
    if request.method == 'GET':
        return render(request,  'register.html')
    elif request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        old_users = User.objects.filter(username=username)
        if old_users:
           return HttpResponse('用户名已注册')
        User.objects.create(username=username, password=password)
        return HttpResponse('注册成功')

# Create your views here.
